package architect;

/**
 * @description: 多线程
 * @author: guanxin
 * @date: 2018/12/6 9:38 PM
 * @since: JDK 1.8
 */
public class MainThread extends Thread {

    private Thread prevThread;

    private int index;

    public MainThread(Thread prevThread, int i) {
        this.prevThread = prevThread;
        this.index = i;
    }

    @Override
    public void run() {
        try {
            this.prevThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("num: " + Integer.toString(index));
    }

    public static void main(String[] args) {
        Thread currentThread = Thread.currentThread();

        for (int i = 0; i < 10; i++) {
            MainThread mainThread = new MainThread(currentThread, i);
            mainThread.start();
            currentThread = mainThread;
        }

        System.out.println("main thread");
    }
}
